package com.ambientrs.bot.gui;

import com.ambientrs.script.Manifest;

import javax.swing.*;

public class ScriptSelector extends JFrame {

    private static final long serialVersionUID = 1L;

    private JTable table;

    public ScriptSelector(Manifest[] scripts) {
        setTitle("Script Selector");
        setSize(600, 450);
        setResizable(false);
        setLayout(null);
        setLocationRelativeTo(null);
        String[] columns = {"Name", "Authors", "Version", "Description"};
        String[][] manifests;
        if (scripts != null) {
            manifests = new String[scripts.length][4];
            for (int i = 0; i < scripts.length; i++) {
                StringBuilder author = new StringBuilder();
                for (int j = 0; j < scripts[i].authors().length; j++) {
                    if (j != 0)
                        author.append(", ");
                    author.append(scripts[i].authors()[j]);
                }
                manifests[i] = new String[]{scripts[i].name(), new String(author),
                        scripts[i].version() + "", scripts[i].category()};
            }
        } else {
            manifests = new String[][]{};
        }
        table = new JTable(manifests, columns);
        table.setBounds(0, 0, 600, 415);
        // TODO add combo box, filter, start button, and gui impl
        add(table);
    }

    public void clearComponents() {
        remove(table);
    }

}
